package com.rq.base.net;

import com.rq.base.util.GsonUtil;

public class NetworkRequestJudge {
    Judge mJudge = new DefaultJudge();

    public interface Judge {
        /**
         * 数据解析
         * @param json
         * @param clazz
         * @param <T>
         * @return
         */
        <T> T toBean(String json, Class<T> clazz);

        boolean isOk(Object obj);
    }

    public class DefaultJudge implements Judge {

        @Override
        public <T> T toBean(String json, Class<T> clazz) {
            return GsonUtil.getBean(json, clazz);
        }

        @Override
        public boolean isOk(Object obj) {
            return obj != null;
        }
    }

    public static Judge get() {
        return new NetworkRequestJudge().mJudge;
    }

}
